home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / 215_01.zip / BBSCLOCK.C < prev    next >
Text File  |  1980-01-01  |  8KB  |  381 lines

  1. /*
  2.     bbsclock.c
  3.  
  4.     This program will...
  5.         access the Hayes Chronograph using 
  6.         the Godbout Interfacer IV I/O board.
  7.  
  8.     05-07-83 v1.0    started writing
  9.     06-19-83 v1.0    last updated
  10.  
  11. */
  12.  
  13. #include "bdscio.h"
  14.  
  15. #define VERSION   "1.0"
  16. #define ESC      0x1b
  17. #define CR      0x0d
  18. #define LF      0x0a
  19. #define CLEAR      'E'
  20.  
  21. #define GB4PDATA 0x10            /* data port   */
  22. #define GB4PSTAT GB4PDATA+1        /* status port */
  23. #define GB4PCMD  GB4PDATA+3        /* command port */
  24. #define GB4PSEL  GB4PDATA+7        /* user select port */
  25. #define GB4PMODE GB4PDATA+2        /* mode port */
  26. #define USER      6            /* user number 6=chronograph */
  27.  
  28. #define SDREADY      0x80            /* data set ready */
  29. #define SCARRIER  0x40            /* carrier detect */
  30. #define SFRAME    0x20            /* framing error  */
  31. #define SOVERRUN  0x10            /* overrun error  */
  32. #define SDAV      0x02            /* character waiting */
  33. #define SEMPTY      0x01            /* transmit buffer empty */
  34.  
  35. char    gb4in();
  36.  
  37. char gb4istat()                /* input status routine */
  38. {
  39.     char    byte0,
  40.         byte1;
  41.  
  42.     byte0 = inp(GB4PSTAT);        /* get status byte from port */
  43.     byte1 = byte0 & SDAV;        /* mask all but char avail. bit */
  44.     if (byte1 == SDAV)
  45.     {
  46.         return(0);        /* char waiting, so get out */
  47.     }
  48.     else
  49.     {
  50.         return(1);        /* no char waiting */
  51.     }
  52.  
  53. }
  54.   
  55. char gb4in()                    /* get one byte from the port */
  56. {
  57.     char    byte0;
  58.  
  59.     outp(GB4PSEL,USER);        /* tell who is calling */
  60.       byte0 = inp(GB4PDATA);        /* get byte from port */
  61.  
  62.     return(byte0);
  63. }
  64.  
  65. char gb4sin(string)            /* get a string from the port */
  66. char *string;
  67. {
  68.     char    byte0;
  69.  
  70.     int  i;
  71.  
  72.     i = 0;
  73.     byte0 = 0x00;
  74.     while (byte0 != 0x0d)
  75.     {
  76.  
  77.           while (gb4istat());    /* returns when ready */
  78.         byte0 = gb4in();    /* get a byte */
  79.           *string++ = byte0;
  80.         ++i;
  81.       }
  82.     *string++ = 0x00;
  83. }
  84.  
  85. gb4out(byte2)            /* send one byte to the port */
  86. char byte2;
  87. {
  88.     outp(GB4PSEL,USER);        /* tell who is calling */
  89.     outp(GB4PDATA,byte2);
  90. }
  91.   
  92. gb4sout(string)                /* send a string to the port */
  93. char *string;
  94. {
  95.     char bytex;
  96.  
  97.     while (*string)
  98.     {
  99.         bytex = (*string++);
  100.  
  101.         while (gb4ostat());
  102.           gb4out(bytex);
  103.     }
  104. }
  105.  
  106. gb4ostat()            /* returns 0 if buffer empty */
  107. {                /* returns 1 if buffer not empty */
  108.     char    byte0,
  109.         byte1;
  110.  
  111.     byte0 = inp(GB4PSTAT);
  112.     byte1 = byte0 & SEMPTY;    /* mask all but xmit buffer empty bit */
  113.     if (byte1 == SEMPTY)
  114.     {
  115.         return(0);    /* yup, it's empty */
  116.     }
  117.     else
  118.     {
  119.         return(1);    /* nope, it's not */
  120.     }
  121. }
  122.  
  123. char gb4init()                /* init godbout IV i/o board */
  124. {
  125.     outp(GB4PSEL,USER);        /* tell who is calling */
  126.     outp(GB4PMODE,0x6e);
  127.     outp(GB4PMODE,0x75);            /* 300 baud */
  128.     outp(GB4PCMD,0x27);
  129.     gb4sout("ATLC\r");        /* clear line feed option */
  130.     gb4gobble();            /* gobble any response */
  131.     gb4sout("ATVT\r");        /* clear time separator */
  132.     gb4gobble();            /* gobble any response */
  133.     gb4sout("ATVD\r");        /* clear date separator */
  134.     gb4gobble();            /* gobble any response */
  135. }
  136.  
  137. gb4gobble()
  138. {
  139.     char    byte;
  140.  
  141.     byte = 0x00;
  142.     while (byte != 0x0d)
  143.     {
  144.         while (gb4istat());
  145.         byte = gb4in();
  146.     }
  147. }
  148.  
  149.  
  150. gettime(_time)
  151. char    *_time;
  152. {
  153.     char    newtime[15],
  154.         time0[15],
  155.         *timeptr;
  156.  
  157.     timeptr = &time0;
  158.     newtime[0] = "\0";
  159.     gb4init();        /* init i/o board */
  160.     gb4sout("ATRT\r");    /* ask for time */
  161.     gb4sin(time0);        /* time in HHMMSSx where x=A(M) or P(M) */
  162.  
  163.     newtime[0] = (*timeptr++);
  164.     newtime[1] = (*timeptr++);
  165.     newtime[2] = ':';
  166.     newtime[3] = (*timeptr++);
  167.     newtime[4] = (*timeptr++);
  168.     newtime[5] = ':';
  169.     newtime[6] = (*timeptr++);
  170.     newtime[7] = (*timeptr++);
  171.     newtime[8] = ' ';
  172.     newtime[9] = (*timeptr++);
  173.     newtime[10]= 'M';
  174.     newtime[11]= '\0';
  175.         
  176.     strcpy(_time,newtime);    /* copy newtime to returned time */
  177. }    
  178.  
  179. getdate(_mm,_dd,_yy,_month,_day,_year,_date,_week)
  180. char    *_mm,        /* 2 digit */
  181.     *_dd,        /* 2 digit */
  182.     *_yy,        /* 2 digit */
  183.     *_month,    /* long */
  184.     *_day,        /* long */
  185.     *_year,        /* long */
  186.     *_date,        /* long month day, year */
  187.     *_week;        /* day of week */
  188. {
  189.     char    date1[5],
  190.         date2[30];
  191.  
  192.     gb4init();        /* init i/o board */
  193.     strcpy(date1,"\0");    /* init strings */
  194.     strcpy(date2,"\0");
  195.  
  196.     gb4sout("ATRW\r");    /* ask for day of week */
  197.     gb4sin(date2);        /* week is 0=mon,1=tue,... */
  198.  
  199.     switch (date2[0])
  200.     {
  201.         case '0':
  202.             strcpy(_week,"Monday ");
  203.             break;
  204.         case '1':
  205.             strcpy(_week,"Tuesday ");
  206.             break;
  207.         case '2':
  208.             strcpy(_week,"Wednesday ");
  209.             break;
  210.         case '3':
  211.             strcpy(_week,"Thursday ");
  212.             break;
  213.         case '4':
  214.             strcpy(_week,"Friday ");
  215.             break;
  216.         case '5':
  217.             strcpy(_week,"Saturday ");
  218.             break;
  219.         case '6':
  220.             strcpy(_week,"Sunday ");
  221.             break;
  222.         default:
  223.             strcpy(_week,"Unknown ");
  224.             break;
  225.     }
  226.  
  227.     strcpy(date2,"\0");
  228.  
  229.     gb4sout("ATRD\r");    /* ask for the date */
  230.     gb4sin(date2);        /* date is YYMMDD */
  231.  
  232.     if (date2[2] == '0')    /* if MM < 10 */
  233.     {
  234.         switch (date2[3])
  235.         {
  236.             case '1':
  237.                 strcpy(_month,"January ");    
  238.                 break;
  239.             case '2':
  240.                 strcpy(_month,"February ");    
  241.                 break;
  242.             case '3':
  243.                 strcpy(_month,"March ");    
  244.                 break;
  245.             case '4':
  246.                 strcpy(_month,"April ");
  247.                 break;
  248.             case '5':
  249.                 strcpy(_month,"May ");    
  250.                 break;
  251.             case '6':
  252.                 strcpy(_month,"June ");
  253.                 break;
  254.             case '7':
  255.                 strcpy(_month,"July ");    
  256.                 break;
  257.             case '8':
  258.                 strcpy(_month,"August");
  259.                 break;
  260.             case '9':
  261.                 strcpy(_month,"September ");
  262.                 break;
  263.             default:
  264.                 strcpy(_month,"Unknown ");
  265.                 break;
  266.         }
  267.     }
  268.     else
  269.     {
  270.         switch(date2[3])    /* MM > 9 */
  271.         {
  272.             case '0':
  273.                 strcpy(_month,"October ");
  274.                 break;
  275.             case '1':
  276.                 strcpy(_month,"November ");
  277.                 break;
  278.             case '2':
  279.                 strcpy(_month,"December ");
  280.                 break;
  281.             default:
  282.                 strcpy(_month,"Unknown ");
  283.                 break;
  284.         }
  285.     }
  286.  
  287.     substr(date2,_day,5,2);
  288.     substr(date2,_dd,5,2);
  289.  
  290.     substr(date2,_yy,1,2);
  291.     strcpy(date1,"19");
  292.     strcat(date1,_yy);
  293.     strcpy(_year,date1);
  294.  
  295.     substr(date2,_mm,3,2);
  296.  
  297.     strcpy(_date,"\0");    /* clear date */
  298.     strcat(_date,_month);    /* then concat the month,etc. */
  299.     strcat(_date,_day);
  300.     strcat(_date,", ");
  301.     strcat(_date,_year);
  302. }
  303.  
  304.  
  305.  
  306. /*    t    e    s    t    i    n    g
  307. main(argc,argv)
  308. int    argc;
  309. char    *argv[];
  310.  
  311.  
  312. {
  313.  
  314.         char    answer[15],           /* hold answer from chrono */
  315.             byte,
  316.         mm[3],
  317.         dd[3],
  318.         yy[3],
  319.         month[16],
  320.         day[3],
  321.         year[5],
  322.         date[27],
  323.         week[13];        /* day of week */
  324.  
  325.         int    stat,
  326.             ans,
  327.         i;
  328.  
  329.     int    debug;
  330.  
  331.  
  332.     debug = FALSE;
  333.     strcpy(mm,"\0");
  334.     strcpy(dd,"\0");
  335.     strcpy(yy,"\0");
  336.     strcpy(month,"\0");
  337.     strcpy(day,"\0");
  338.     strcpy(year,"\0");
  339.     strcpy(date,"\0");
  340.     strcpy(week,"\0");
  341.  
  342.     gb4init();            /* init i/o board */
  343.  
  344.     clear();
  345.     printf("\nStarting Setclock\n");
  346.     printf("    Version %s\n",VERSION);
  347.   
  348.     if (argc > 1)
  349.     {
  350.         printf("\nargc=%02u  argc hex=%04x\n",argc,argc);
  351.         for (i = 1; i < argc; i++)
  352.                 printf("argv[%02u]=%s \n",i,argv[i]);
  353.         if (strcmp(*++argv,"DEBUG") == 0)
  354.         {
  355.                 printf("\nDebug mode on!\n\n");
  356.                 debug = TRUE;
  357.             *--argv;    /* reset pointer */
  358.         }
  359.     }
  360.  
  361. again:
  362.     printf("asking for time\n");
  363.  
  364.     gettime(answer);
  365.     printf("\nThe time is %s\n",answer);
  366.     prthex(answer);        /* print in hex */
  367.  
  368.     getdate(mm,dd,yy,month,day,year,date,week);
  369.     printf("\nThe date is %s\n",date);
  370.     prthex(date);
  371.     printf("mm=%s dd=%s yy=%s month=%s day=%s year=%s date=%s week=%s\n",
  372.         mm,dd,yy,month,day,year,date,week);
  373.  
  374. }
  375. /*
  376.  
  377.     t    e    s    t    i    n    g
  378. */
  379.  
  380. /*    end of program      */
  381.